package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {


    /**
     * 条件查询
     *
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 更新数量
     *
     * @param shoppingCart
     */
    @Update("update shopping_cart set number = #{number}  where id = #{id} ")
    void updateNumberById(ShoppingCart shoppingCart);

    /**
     * 添加数据
     *
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart " +
            "(create_time, amount, number, dish_flavor, setmeal_id, dish_id, user_id, image, name) " +
            "values ( #{createTime} , #{amount} , #{number} , #{dishFlavor} , #{setmealId} ," +
            " #{dishId} , #{userId} , #{image} , #{name} )")
    void insert(ShoppingCart shoppingCart);

    /**
     * 清空购物车
     *
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void clean(Long userId);

    /**
     * 根据id 删除购物车中一个商品
     *
     * @param id
     */
    @Delete("delete from shopping_cart  where id = #{id}")
    void deleteById(Long id);
}
